$(function () {
    $("body").on('click','#sendRand',function () {
        var _that = this;
        disabledSend(_that);
        var mobile = $("input[name='mobile']").val();
        sendCode(mobile,2,function () {
            $(_that).hide();
            $("#noSendRand").show();
            $("#noSendRand").text('(60s)获取验证码');
            var time = 60;
            var inter = setInterval(function () {
                time --;
                if(time<=0){
                    window.clearInterval(inter);
                    $(_that).show();
                    $("#noSendRand").hide();
                    $("#noSendRand").text('');
                    relieveSend(_that);
                }else{
                    $("#noSendRand").text('('+time+'s)获取验证码');
                }
            },1000);
        },_that);
    }).on('click','#submitRetrievePassword',function () {//找回密码提交
        var mobile = $("input[name='mobile']").val();
        var mobileCode = $("input[name='mobileCode']").val();
        var passWord = $("input[name='passWord']").val();
        var confirmPwd = $("input[name='confirmPwd']").val();
        if(passWord !=null && $.trim(passWord) !=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            passWord = encrypt.encrypt(passWord);
        }
        if(confirmPwd !=null && $.trim(confirmPwd) !=''){
            var encrypt = new JSEncrypt();
            encrypt.setPublicKey(publicKey);
            confirmPwd = encrypt.encrypt(confirmPwd);
        }
        $.ajax({
            url:baseloaction +'/web/user/ajax/retrievePassword',
            type:'post',
            dataType:'json',
            data:{
                'mobile':mobile,
                'mobileCode':mobileCode,
                'password':passWord,
                'confirmPwd':confirmPwd,
                "sign":sign
            },
            success:function (result) {
                if(result.success==true){
                    $("input[name='mobile']").val('');
                    $("input[name='mobileCode']").val('');
                    $("input[name='passWord']").val('');
                    $("input[name='confirmPwd']").val('');
                    $("#sendRand").show()
                    $("#noSendRand").hide();
                    icModale(0,'',result.message);
                    window.setTimeout("window.location='/web/user/login'",500);
                }else{
                    sign = result.keyMap.sign;
                    publicKey = result.keyMap.publicKey;
                    setErrorMessage(result.message);
                }
            },
            error:function (error) {
                icModale(0,'','系统错误，提交失败');
            }
        });
    }).on('click','.input-group>.input-lg',function () {
        $(".errorMessage").hide();
        $(".errorTips").text('');
    });

    /**
     * 设置错误信息
     * @param message
     */
    function setErrorMessage(message) {
        $(".errorMessage").show();
        $(".errorTips").text(message);
    }
});